const app = getApp()
const _ = require('underscore')
Page({
    data: {
        list: [],
        keywords: ''
    },

    onLoad() {
        app.globalData.db.collection('minipet')
            .get({
                success: (res) => {
                    this.setData({
                        list: res.data
                    })
                }
            })
    },

    handleInput: _.debounce( function(e) {
        this.setData({
            keywords: e.detail.value
        })
        this.doSearch()
    }, 300),

    doSearch() {
        const db = app.globalData.db
        db.collection('minipet')
            .where({
                message: db.RegExp({
                    regexp: this.data.keywords,
                    options: 'i',
                })
            }).get({
                success: (res) => {
                    this.setData({
                        list: res.data
                    })
                }
            })
    }
})